/**
 *Copyright (c) 2024 watereyes
 * safetymanagement is licensed under Mulan PubL v2.
 * You can use this software according to the terms and conditions of the Mulan
 * PubL v2.
 * You may obtain a copy of Mulan PubL v2 at:
 *          http://license.coscl.org.cn/MulanPubL-2.0
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PubL v2 for more details.
 */
package com.koron.hazardsource.mapper;

import com.koron.hazardsource.domain.HazardSource;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.koron.ebs.mybatis.EnvSource;

import java.util.List;


public interface HazardSourceMapper {
    /**
     * 新增危险源信息
     *
     * @param table
     * @param bean
     * @return
     */
    Integer insert(@Param("tableName") String table, @Param("bean") HazardSource bean);

    /**
     * 批量新增危险源信息
     *
     * @param table
     * @param hazardList
     * @return
     */
    Integer batchInsertHazard(@Param("tableName") String table, @Param("hazardList") List<HazardSource> hazardList);

    /**
     * 修改危险源信息
     *
     * @param table
     * @param bean
     * @return
     */
    Integer update(@Param("tableName") String table, @Param("bean") HazardSource bean);

    /**
     * 修改危险源状态
     *
     * @param codeList
     * @param state
     * @return
     */
    Integer updateState(@Param("codeList") List<String> codeList, @Param("state") int state);

    /**
     * 修改危险源审批状态
     * @param idList
     * @param fstatusflag
     * @return
     */
    Integer updateFstatusflag(@Param("idList") List<String> idList, @Param("fstatusflag") int fstatusflag);

    /**
     * 根据主键列表删除指定的标准危险源数据
     *
     * @param table
     * @param idList
     * @return
     */
    Integer batchDelete(@Param("tableName") String table, @Param("idList") List<String> idList);

    /**
     * 根据主键获取标准危险源信息
     *
     * @param table
     * @param id
     * @return
     */
    HazardSource queryOneById(@Param("tableName") String table, @Param("id") String id);

    /**
     * 根据危险源编码查询标准危险源信息
     *
     * @param table
     * @param code
     * @return
     */
    HazardSource queryOneByCode(@Param("tableName") String table, @Param("code") String code);


    /**
     * 根据指定条件查询标准危险源数据列表
     * @param tableName
     * @param name
     * @param businessTypeId
     * @param hazardTypeId
     * @param state
     * @param start
     * @param rows
     * @return
     */
    List<HazardSource> selectByCondition(@Param("tableName") String tableName, @Param("name") String name, @Param("indicationLevelId") String indicationLevelId,
    		@Param("riskLevelStart") Integer riskLevelStart,@Param("riskLevelEnd") Integer riskLevelEnd,@Param("businessTypeId") String businessTypeId,
                                         @Param("hazardTypeId") String hazardTypeId, @Param("fitAllBusiness") Boolean fitAllBusiness,
                                         @Param("state") Integer state, @Param("start") Integer start, @Param("rows") Integer rows);

    /**
     * 获取草稿列表
     *
     * @param userCode
     * @return
     */
    List<HazardSource> getDraftList(@Param("userCode") String userCode);
 
    /**
     * 根据指定条件统计总数
     *
     * @param tableName
     * @param name
     * @param businessTypeId
     * @param hazardTypeId
     * @param state
     * @return
     */
    Integer countByCondition(@Param("tableName") String tableName, @Param("name") String name, @Param("indicationLevelId") String indicationLevelId,
    		@Param("riskLevelStart") Integer riskLevelStart,@Param("riskLevelEnd") Integer riskLevelEnd,@Param("businessTypeId") String businessTypeId,
                             @Param("hazardTypeId") String hazardTypeId, @Param("fitAllBusiness") Boolean fitAllBusiness, @Param("state") Integer state);

    /**
     * 根据指定的id列表查询数据
     *
     * @param table
     * @param idList
     * @return
     */
    List<HazardSource> queryByIdList(@Param("tableName") String table, @Param("idList") List<String> idList);

    @Select("select * from hazard_source_history where code=#{code} and fstatusflag=2")
    List<HazardSource> queryHstory(@Param("code") String code);
    
    @Delete("delete from hazard_source_history where id=#{id}")
    Integer deleteDraft(@Param("id") String id);
    
    @Update("update hazard_source_history set code=#{code} where id=#{id}")
    Integer updateCode (@Param("id") String id,@Param("code") String code);
}
